package com.ziyun.erp.modules.logistics.service.impl;

import io.renren.common.utils.StringUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.ziyun.erp.modules.logistics.dao.LogisticsTypeDao;
import com.ziyun.erp.modules.logistics.entity.LogisticsTypeEntity;
import com.ziyun.erp.modules.logistics.service.LogisticsTypeService;


@Service("logisticsTypeService")
public class LogisticsTypeServiceImpl extends ServiceImpl<LogisticsTypeDao, LogisticsTypeEntity> implements LogisticsTypeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String logisticsName = StringUtil.getRequestParamString(params.get("logisticsName"));
        Integer logisticsCategory = StringUtil.getRequestParamInteger(params.get("logisticsCategory"));

        Page<LogisticsTypeEntity> page = this.selectPage(
                new Query<LogisticsTypeEntity>(params).getPage(),
                new EntityWrapper<LogisticsTypeEntity>()
                    .eq("`delete`",0)
                    .like(StringUtil.isNotNull(logisticsName),"logistics_name",logisticsName)
                    .eq(StringUtil.isNotNull(logisticsCategory),"logistics_category",logisticsCategory)
                    .orderBy("order_num")
        );

        return new PageUtils(page);
    }

    @Override
    public void deleteUpdate(Integer logisticsId, Long userId) {
        Map<String,Object> updateMap = new HashMap<>();
        updateMap.put("delete",1);
        updateMap.put("update_name",userId);
        baseMapper.updateByMap(updateMap,logisticsId);

    }

    @Override
    public List<Map<Integer, String>> queryTypeList() {
        return baseMapper.queryTypeList();
    }

}
